//
//  CountDownViewController.m
//  Olympics
//
//  Created by 马滕亚 on 2020/5/24.
//  Copyright © 2020 M.Y.A. All rights reserved.
//

#import "CountDownViewController.h"

@interface CountDownViewController ()


@property (weak, nonatomic) IBOutlet UILabel *countDownLabel;

@end

@implementation CountDownViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = UIColor.whiteColor;

    
    // 创建NSDateComponents对象
    NSDateComponents *comps = [[NSDateComponents alloc] init];
    // 设置NSDateComponents中的年月日
    [comps setYear:2020];
    [comps setMonth:12];
    [comps setDay:24];
    
    // 创建y日历对象
    // NSCalendarIdentifierGregorian 公历
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    // 获得2020-12-24的NSDate日期对象
    NSDate *finishDate = [calendar dateFromComponents:comps];
    
    // 获得当前日期到2020-12-24的NSDateComponet对象
    NSDateComponents *components = [calendar components:NSCalendarUnitDay fromDate:[NSDate date] toDate:finishDate options:0];
    // 获取相差时间数
    NSInteger days = [components day];
    self.countDownLabel.text = [NSString stringWithFormat:@"%ld天",(long)days];        
}



@end
